package client

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/client" // 修改导入路径
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var SeriesGroup = core.Group("/client", newSeriesHandler, regSeries, middleware.TokenAuth())

func newSeriesHandler(srv client.IDramaSeriesService) *seriesHandler { // 修改参数类型
	return &seriesHandler{srv: srv}
}

func regSeries(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *seriesHandler) {
		rg.GET("/series/list", handle.list)
		rg.GET("/series/detail", handle.detail)
		rg.POST("/series/add", handle.add)
		rg.POST("/series/edit", handle.edit)
		rg.POST("/series/del", handle.del)
	})
}

type seriesHandler struct {
	srv client.IDramaSeriesService // 修改字段类型
}

// list series列表
func (hd seriesHandler) list(c *gin.Context) {
	var page request.PageReq
	var listReq req.DramaSeriesListReq // 添加包前缀
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}

	res, err := hd.srv.List(page, listReq) // 修正变量名为 hd
	response.CheckAndRespWithData(c, res, err)
}

// detail series详情
func (hd seriesHandler) detail(c *gin.Context) {
	var detailReq req.DramaSeriesDetailReq // 添加包前缀
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
		return
	}
	res, err := hd.srv.Detail(detailReq.SeriesId)
	response.CheckAndRespWithData(c, res, err)
}

// add series新增
func (hd seriesHandler) add(c *gin.Context) {
	var addReq req.DramaSeriesAddReq // 添加包前缀
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Add(addReq))
}

// edit series编辑
func (hd seriesHandler) edit(c *gin.Context) {
	var editReq req.DramaSeriesEditReq // 添加包前缀
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Edit(editReq))
}

// del series删除
func (hd seriesHandler) del(c *gin.Context) {
	var delReq req.DramaSeriesDelReq // 添加包前缀
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Del(delReq.SeriesId))
}
